import { INCREMENT, DECREMENT } from '@/store/actionsType/xyf/xyf-type'

const initState = {
    count: 0
}

export default function counter(state = initState, action) {     //两个参数是固定的，state值，初始值为0（形参默认值）
    //action 是一个对象，有两个属性，一个type, 一个data
    switch (action.type) {
        case INCREMENT:    //加
            return {
                ...state,
                count: state.count + action.data
            }
        case DECREMENT:    //减
            return{
                ...state,
                count: state.count - action.data
            }
        default:            //返回默认值
            return state
    }
}